﻿using UnityEngine;
using System.Collections;

public class CEventDataItem : MonoBehaviour {

	public GameObject m_WaitingBar;
	public UITexture  m_Circle;
	public UITexture  m_Texture;
	public int 		m_nID;
	bool m_bLoaded;
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		m_Circle.transform.RotateAround (Vector3.back, Time.deltaTime * 2);
		
		if (m_bLoaded)
			m_WaitingBar.gameObject.SetActive(false);
	}
	
	public IEnumerator SetTexture()
	{
		VR_AR.EVENT_INFO eventInfo = JsonDataRead.Instance.eventData [JsonDataRead.Instance.curEventID];
		Texture tex = JsonDataRead.Instance.FindTextureByUrl (eventInfo.eventImages[m_nID].sImageFilePath);
		
		if (tex == null) {
			WWW www = new WWW (JsonDataRead.Instance.DataPath + eventInfo.eventImages[m_nID].sImageFilePath);
			yield return www;
			m_Texture.mainTexture = www.texture;
			JsonDataRead.Instance.AddTexture(eventInfo.eventImages[m_nID].sImageFilePath, www.texture);
			m_bLoaded = true;
		} else {
			m_Texture.mainTexture = tex;
			m_bLoaded = true;
		}
	} 
}